package com.yociyy.sms.validate.code;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @author: YoCiyy
 * @date: 2020/5/25
 */
@RestController
public class ValidateCodeController {

	// private static final String SESSION_KEY = "SESSION_KEY_IMAGE_CODE";
	//
	// private SessionStrategy sessionStrategy = new HttpSessionSessionStrategy();
	//
	// @Autowired
	// private ValidateCodeGenerator validateCodeGenerator;
	//
	// @Autowired
	// private ValidateCodeGenerator smsCodeGenerator;
	//
	// @Autowired
	// private SmsCodeSender smsCodeSender;

	@Autowired
	private Map<String, ValidateCodeProcessor> validateCodeProcessors;

//	@GetMapping(SmsConstants.DEFAULT_VALIDATE_CODE_URL_PREFIX + "/{type}")
	public void createCode(HttpServletRequest request, HttpServletResponse response, @PathVariable String type) throws Exception {
//		validateCodeProcessors.get(type + "CodeProcessor").create(new ServletWebRequest(request, response));
	}

//	@GetMapping("code/image")
//	public void createImageCode(HttpServletRequest request, HttpServletResponse response) throws IOException {
//		ImageCode imageCode = (ImageCode) validateCodeGenerator.generate(new ServletWebRequest(request, response));
//		sessionStrategy.setAttribute(new ServletWebRequest(request), SESSION_KEY, imageCode);
//		ImageIO.write(imageCode.getImage(), "JPEG", response.getOutputStream());
//	}
//
//	@GetMapping("code/sms")
//	public void createSmsCode(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletRequestBindingException {
//		SmsCode smsCode = (SmsCode) validateCodeGenerator.generate(new ServletWebRequest(request, response));
//		sessionStrategy.setAttribute(new ServletWebRequest(request), SESSION_KEY, smsCode);
//		String mobile = ServletRequestUtils.getRequiredStringParameter(request, "mobile");
//		smsCodeSender.send(mobile, smsCode.getCode());
//	}

}
